Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.6K
Views
Error con datos JSON ("Se esperaba un objeto, matriz o literal JSON")

Estoy siguiendo un tutorial de JSON y me encontré con un problema.

Estoy usando Visual Studio Code y tengo un archivo HTML, un archivo JS y un archivo JSON. Aunque los datos en el archivo JSON (según mi leal saber y entender) están formateados correctamente, VSCode me da el siguiente error:

Se esperaba un objeto JSON, una matriz o un literal.

En este momento, el archivo JS está vacío. El código en mi archivo HTML es el siguiente:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h1>SANDBOX</h1> <div class="output"> </div> </body> <script src="data.json"></script> <script src="app.js"></script> </html>

y los datos en mi archivo .JSON son:

 const json = { "books": [{ "title": "Learn to Code", "author": "John Smith", "isbn": "324-23243" }, { "title": "The Adventures JSON", "author": "Jason Jones", "isbn": "3324-2-444" }, { "title": "New Objects", "author": "Jane Doe", "isbn": "2343-234-2433" }] };

No entiendo por qué me sale este error.

Cosas que he probado:

  1. Siguiendo el tutorial - El tutor no parece tener este problema, por alguna razón.

  2. Envolver los datos JSON entre llaves: esto solo arroja tres errores más: las claves de propiedad deben estar entre comillas dobles, se esperan dos puntos y se espera el final del archivo.

  3. Buscar en este sitio preguntas similares: encontré preguntas similares, pero las soluciones ofrecidas no resuelven mi problema. Siempre me queda el error original, 'Se esperaba un objeto, matriz o literal JSON'.

Cualquier ayuda que pueda proporcionar sería muy apreciada.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

no puedes usar javascript dentro del archivo .json

cambie el archivo .json a

 [{ "title": "Learn to Code", "author": "John Smith", "isbn": "324-23243" }, { "title": "The Adventures JSON", "author": "Jason Jones", "isbn": "3324-2-444" }, { "title": "New Objects", "author": "Jane Doe", "isbn": "2343-234-2433" }]

en su lugar, cargue su archivo json dentro de app.js

 const books = require("my.json")

PERO

si desea usarlo así, debe cambiar el formato de my.json a my.js

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!